﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EasyCalcLib
{
    public class Calc
    {
        string[] args;
        public Calc(string[] args)
        {
            this.args = args;
        }
        public double calculer()
        {
            if (args == null || args.Length != 3)
            {
                throw new Exception("Le nombre d'arguments est invalide");
            }
            try
            {
                double resultat;
                switch (args[2])
                {
                    case "+":
                        resultat = addition(Int32.Parse(args[0]), Int32.Parse(args[1]));
                        break;
                    case "-":
                        resultat = soustraction(Int32.Parse(args[0]), Int32.Parse(args[1]));
                        break;
                    case "*":
                        resultat = multiplication(Int32.Parse(args[0]), Int32.Parse(args[1]));
                        break;
                    case "/":
                        resultat = division(Int32.Parse(args[0]), Int32.Parse(args[1]));
                        break;
                    default: throw new Exception("Operateur inconnu ! + - * /");
                }
                return resultat;
            }
            catch (Exception e)
            {
                throw new Exception("Erreur pendant le calcul : " + e.Message);
            }
        }
        private int addition(int x, int y)
        {
            return x + y;
        }

        private int soustraction(int x, int y)
        {
            return x - y;
        }
        private int multiplication(int x, int y)
        {
            return x * y;
        }
        private double division(int x, int y)
        {
            return Math.Round((double)x / y, 2);
        }


    }
}
